#!/bin/bash

set -e  # 遇到错误立即退出

# 获取脚本所在绝对路径
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# 执行构建
echo "Starting build process..."
pyinstaller --onefile \
    --distpath "${SCRIPT_DIR}/build/dist" \
    --workpath "${SCRIPT_DIR}/build/temp" \
    --specpath "${SCRIPT_DIR}/build/specs" \
    --noconfirm "${SCRIPT_DIR}/app_main.py"

# 创建日志目录
echo "Creating logs directory..."
mkdir -p "${SCRIPT_DIR}/build/dist/logs"

# 复制主程序
echo "Copying source file..."
cp -f "${SCRIPT_DIR}/app_config.yaml" "${SCRIPT_DIR}/build/dist/"

# 输出完成信息
echo -e "\n\033[32mBuild completed!\033[0m"
echo "Executable and logs: ${SCRIPT_DIR}/build/dist"
echo "Copied files:"
ls -l "${SCRIPT_DIR}/build/dist/app_config.yaml"

# 交互暂停
read -rp $'\nPress any key to exit...' -n1